package com.yc.meeting_attendance.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yc.meeting_attendance.R;
import com.yc.meeting_attendance.entity.MeetingResutl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by PC on 2016/12/21.
 */

public class MeetingRecyclerAdapter extends RecyclerView.Adapter<MeetingRecyclerAdapter.ViewHolder> {
    private List<MeetingResutl> items=new ArrayList<>();
    private Context context;
    public MeetingRecyclerAdapter(Context context) {
        this.context = context;
    }


    public void setDate( List<MeetingResutl> items) {
        this.items.addAll(items);
        notifyDataSetChanged();
    }

    public void clearDate() {
        items.clear();
        notifyDataSetChanged();
    }
    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_meeting, viewGroup, false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }


    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {

        viewHolder.tv_item_normal_title.setText(items.get(position).getMeetingName());
        viewHolder.tv_item_sub_title.setText(items.get(position).getMeetingContent()+"");
        viewHolder.tv_item_date.setText(items.get(position).getBegin()+"-"+items.get(position).getEnd());


            Glide.with(context).load(R.mipmap.index_huiyi_icon_one)
                 .into(viewHolder.iv_item_title);


    }

    //获取数据的数量
    @Override
    public int getItemCount() {
        return items.size();
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_item_normal_title;
        TextView tv_item_sub_title;
        TextView tv_item_date;
        ImageView iv_item_title;

        public ViewHolder(View view) {
            super(view);
            tv_item_normal_title = (TextView) view.findViewById(R.id.tv_item_normal_title);
            tv_item_sub_title = (TextView) view.findViewById(R.id.tv_item_sub_title);
            tv_item_date = (TextView) view.findViewById(R.id.tv_item_date);
            iv_item_title=(ImageView)view.findViewById(R.id.iv_item_title);
        }
    }

}
